from numpy import exp, pi

def theta(a,b,z,t):
    temp = (0 + 0j)
    temp = temp + helperFunc(a,b,z,t,0)
    for n in range(1,1000):
        temp = temp + helperFunc(a,b,z,t,n)
        temp = temp + helperFunc(a,b,z,t,-n)
    return temp

def jacobiTheta(n,m,z,t):
    a = 0.5 if n == 1 else 0.0
    b = 0.5 if m == 1 else 0.0
    return theta(a,b,z,t)

def thetaDeriv(a,b,z,t):
    temp = (0 + 0j)
    temp = temp + 2*pi*(0+1j)*a*helperFunc(a,b,z,t,0)
    for n in range(1,1000):
        temp = temp + 2*pi*(0+1j)*(n+a)*helperFunc(a,b,z,t,n)
        temp = temp + 2*pi*(0+1j)*(-n+a)*helperFunc(a,b,z,t,-n)
    return temp

def thetaSecondDeriv(a,b,z,t):
    temp = (0 + 0j)
    temp = temp + ((2*pi*(0+1j)*a)**2)*helperFunc(a,b,z,t,0)
    for n in range(1,1000):
        temp = temp + ((2*pi*(0+1j)*(n+a))**2)*helperFunc(a,b,z,t,n)
        temp = temp + ((2*pi*(0+1j)*(-n+a))**2)*helperFunc(a,b,z,t,-n)
    return temp

def helperFunc(a,b,z,t,n):
    return exp(pi * (0 + 1j) * (n+a) * ((n+a)*t + 2*(z+b)))
